<?php
namespace backend\controllers;
use common\Session;
use yii\web\Controller;
use backend\models\Login;
use yii;
use yii\helpers\Url;
//use backend\controllers\ValidateCode;
/**
 * Created by PhpStorm.
 * User: zhn
 * Date: 2015/8/11
 * Time: 10:28
 * 登录控制器
 */
class LoginController extends Controller{
    public $layout = "login";
    public function actionIndex(){
        $model=new Login();
        if($model->load(Yii::$app->request->post()) && $model->validate()){
            Session::addSession($model->_user['user']);
            return $this->redirect(['/home/index']);//成功后对页面进行跳转
        }
        return $this->render('index',['model'=>$model]);
    }
    //退出登录并删除session
    public function actionLogout(){
        Session::deleteSession();
        $this->redirect(['/login']);//成功后重定向
        //这里不使用reder是因为没有实例化模型
    }
}
?>